﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace Microsoft.Office.Project.EPMAuditing.Library
{

    public delegate bool GetRefreshListenerListCallback();
    public delegate void SetRefreshListenerListCallback(bool refreshListenerList);

    public delegate bool GetStartNewFileCallback();
    public delegate void SetStartNewFileCallback(bool startNewFile);

    // Define custom commands for the EPM Auditing Service.

    public enum SimpleServiceCustomCommand { StopWorker = 128, RestartWorker, CheckWorker, ExecuteRefreshListenerList, StartNewFile };

    [StructLayout(LayoutKind.Sequential)]
    public struct ServiceStatus
    {
        public int serviceType;
        public int currentState;
        public int controlsAccepted;
        public int win32ExitCode;
        public int serviceSpecificExitCode;
        public int checkPoint;
        public int waitHint;
    }

    public enum ServiceState
    {
        Stopped = 0x00000001,
        StartPending = 0x00000002,
        StopPending = 0x00000003,
        Running = 0x00000004,
        ContinuePending = 0x00000005,
        PausePending = 0x00000006,
        Paused = 0x00000007,
    }

    public enum ChangeState
    {
        Unknown,
        Detected,
        Pending,
        SentToProjectSever,
        PSUpdateComplete,
        RemoveFromList,
        Error,
        MoveToArchive
    }

    public static class Utilities
    {
        public static string StreamToString(MemoryStream value)
        {
            value.Position = 0;
            return new StreamReader(value, Encoding.ASCII).ReadToEnd();
        }

        public static MemoryStream StringToStream(string value)
        {
            byte[] byteArray = Encoding.ASCII.GetBytes(value);
            return new MemoryStream(byteArray);
        }


        public static bool DerivedFromBaseFileAuditListener(Type value)
        {
            if (value.BaseType.Name == "BaseFileAuditListener")
                return true;
            else if (value.BaseType.Name != "Object")
                return DerivedFromBaseFileAuditListener(value.BaseType);
            else
                return false;
        }

    }
}
